using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LibreriaWC
{
    /// <summary>
    /// WebControl para generar botonera.
    /// </summary>
    [ParseChildren(true)]
    [PersistChildren(false)]
    [ToolboxData("<{0}:BotoneraNew runat=server></{0}:BotoneraNew>")]
    public class BotoneraNew : Panel
    {
        List<ITemplate> botones = new List<ITemplate>();
        Table tabla = new Table();
        TableRow tr = null;
        TableCell tc = null;

        public BotoneraNew()
            : base()
        {
        }

        private ITemplate _boton;

        [TemplateInstance(TemplateInstance.Single)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [Browsable(false)]
        public ITemplate Boton
        {
            get
            {
                return _boton;
            }
            set
            {
                _boton = value;
            }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();

            tabla.CellPadding = 0;
            tabla.CellSpacing = 0;

            //Agregar una fila y una columna con una imagen transparente.
            //Le pongo fondo blanco.
            tr = new TableRow();
            tc = new TableCell();
            tc.Width = Unit.Percentage(100);
            tc.BackColor = System.Drawing.Color.White;
            Image img = new Image();
            img.ImageUrl = (!this.DesignMode ? HttpContext.Current.Request.ApplicationPath + "/Images/trans.gif" : "");
            img.Width = this.Width;
            img.Height = Unit.Pixel(2);
            tc.Controls.Add(img);
            tr.Cells.Add(tc);
            tabla.Rows.Add(tr);

            //Agregar una fila y una columna con una imagen transparente para dejar un espacio.
            tr = new TableRow();
            tc = new TableCell();
            img = new Image();
            img.ImageUrl = (!this.DesignMode ? HttpContext.Current.Request.ApplicationPath + "/Images/trans.gif" : "");
            img.Width = Unit.Pixel(1);
            img.Height = Unit.Pixel(3);
            tc.Controls.Add(img);
            tr.Cells.Add(tc);
            tabla.Rows.Add(tr);

            tr = new TableRow();
            tc = new TableCell();
            tc.Style.Add(HtmlTextWriterStyle.PaddingRight, "5px");
            tc.HorizontalAlign = HorizontalAlign.Right;
            tr.Cells.Add(tc);
            tabla.Rows.Add(tr);

            if (Boton != null)
            {
                Boton.InstantiateIn(tc); 
            }

            //Agregar una fila y una columna con una imagen transparente para dejar un espacio.
            tr = new TableRow();
            tc = new TableCell();
            img = new Image();
            img.ImageUrl = (!this.DesignMode ? HttpContext.Current.Request.ApplicationPath + "/Images/trans.gif" : "");
            img.Width = Unit.Pixel(1);
            img.Height = Unit.Pixel(3);
            tc.Controls.Add(img);
            tr.Cells.Add(tc);
            tabla.Rows.Add(tr);

            Controls.Add(tabla);

            base.CreateChildControls();
        }
    }

    /// <summary>
    /// WebControl para generar item en botonera.
    /// </summary>
    [ParseChildren(true)]
    [PersistChildren(false)]
    [ToolboxData("<{0}:BotoneraItem runat=server></{0}:BotoneraItem>")]
    public class BotoneraItem : Panel
    {
        public BotoneraItem()
            : base()
        {
        }
    }
}
